home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 9713 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  3.9 KB

  1. Path: mail2news.demon.co.uk!genesis.demon.co.uk
  2. From: Lawrence Kirby <fred@genesis.demon.co.uk>
  3. Newsgroups: comp.lang.c
  4. Subject: Re: malloc question
  5. Date: Tue, 12 Mar 96 21:10:31 GMT
  6. Organization: none
  7. Message-ID: <826665031snz@genesis.demon.co.uk>
  8. References: <4htonk$350@news.hklink.net> <314318AF.30F@iperbole.bologna.it> <4hvaj4$laj@solutions.solon.com> <AD69AACE9668D78B0@mcdiala09.it.luc.edu> <4i1kq3$2m0@solutions.solon.com> <AD6AFF6D9668E8DB7@mcdiala09.it.luc.edu>
  9. Reply-To: fred@genesis.demon.co.uk
  10. X-NNTP-Posting-Host: genesis.demon.co.uk
  11. X-Newsreader: Demon Internet Simple News v1.27
  12. X-Mail2News-Path: genesis.demon.co.uk
  13.  
  14. In article <AD6AFF6D9668E8DB7@mcdiala09.it.luc.edu>
  15.            VArase@varase.it.luc.edu "Verne Arase" writes:
  16.  
  17. >In article <4i1kq3$2m0@solutions.solon.com>,
  18. >seebs@solutions.solon.com (Peter Seebach) wrote:
  19.  
  20. ...
  21.  
  22. >> >And you are _always_ redundant doing so, unless you're passing to a
  23. > >varaidic function or one with no prototype in scope.
  24. >
  25. >I had a pre-ANSI compiler which defined malloc as returning char *.
  26.  
  27. The C language is that which is defined by the ANSI standard. This has been
  28. around long enough to be definitive as to what the C language is. Your
  29. compiler might be called a pre-ANSI or K&R C compiler but it doesn't qualify
  30. when the discussion is simply about unqualified C compilers. That's just the
  31. way things are, at least in comp.lang.c - you'll find that most questions and
  32. answers implicitly assume ANSI C.
  33.  
  34. > >char is not a signed quantity.  char is a quantity which may be signed or
  35. > >unsigned.
  36. >
  37. >Every implementation I've seen makes char signed.
  38.  
  39. That doesn't prove very much. There are real systems out there where
  40. char is unsigned, indeed in some environments char has to be unsigned.
  41. This is because certain characters (A-Z, a-z, 0-9, ! " and others) are
  42. guaranteed to be represented by positive values. If you have, for example,
  43. 8 bit characters and a character set where some or all of these have
  44. representations above 127 (e.g. EBCDIC) then a conforming implementation
  45. has no choice but to make char unsigned. On other systems the
  46. hardware archetecture can simply handle unsigned byte values more
  47. efficiently so the compiler naturally chooses them by default (e.g. ARM).
  48.  
  49. > >It's a question of usage.  An unspecified short, int, or long is *always*
  50. > >signed, so it is clearly desireable for char to be signed.  EOF is
  51. > >negative, and the getc family all return unsigned char or EOF, so it is
  52. > >clearly desireable for char to be unsigned.
  53. >
  54. >While you'd probably want a short, int, or long to be signed, what's the
  55. >percentage of time you actually _want_ char to be signed? And what's the
  56. >percentage of time you gave a hoot whether you had a char * or an unsigned
  57. >char *?
  58.  
  59. OTOH if I want unsigned char I know where to get it.
  60.  
  61. >As for the getc routines: don't have any C references here, but don't they
  62. >return an int?
  63.  
  64. Yes. However the value they return is an unsigned char value converted to
  65. int which is I think what Peter was trying to say. so long as
  66. INT_MAX >= UCHAR_MAX getc() is guaranteed to return a positive value unless
  67. it is flagging an error or end-of-file condition.
  68.  
  69. > >If you don't put in casts, you will get warnings for any conversion not
  70. > >normally correct.  This is helpful.
  71. >
  72. >Depends on the compiler.
  73.  
  74. Only if the compiler is non-conforming. ANSI requires invalid implicit
  75. conversions to be diagnosed.
  76.  
  77. >I've had IDEs where an uncasted pointer conversion just produced an error
  78. >and stopped the compile.
  79.  
  80. The point is that the compiler tells you about it. The language itself makes
  81. no distinction between warning and errors, it only talks about 'diagnostics'.
  82. The compiler can compile and run any source program you give it whatsoever
  83. so long as it gives you at least one diagnostic when the program contains
  84. one or more syntax errors or constraint violations.
  85.  
  86. -- 
  87. -----------------------------------------
  88. Lawrence Kirby | fred@genesis.demon.co.uk
  89. Wilts, England | 70734.126@compuserve.com
  90. -----------------------------------------
  91.